package com.java.project.project.fulu.controller;

import java.util.List;

import com.java.project.project.fulu.domain.Card;
import com.java.project.project.fulu.service.ICardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.java.framework.aspectj.lang.annotation.Log;
import com.java.framework.aspectj.lang.enums.BusinessType;
import com.java.framework.web.controller.BaseController;
import com.java.framework.web.domain.AjaxResult;
import com.java.common.utils.poi.ExcelUtil;
import com.java.framework.web.page.TableDataInfo;

/**
 * 卡密信息Controller
 * 
 * @author admin_dza
 * @date 2021-07-29
 */
@Controller
@RequestMapping("/fulu/card")
public class CardController extends BaseController
{
    private String prefix = "fulu/card";

    @Autowired
    private ICardService cardService;

    @RequiresPermissions("fulu:card:view")
    @GetMapping()
    public String card()
    {
        return prefix + "/card";
    }

    /**
     * 查询卡密信息列表
     */
    @RequiresPermissions("fulu:card:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Card card)
    {
        startPage();
        List<Card> list = cardService.selectCardList(card);
        return getDataTable(list);
    }

    /**
     * 导出卡密信息列表
     */
    @RequiresPermissions("fulu:card:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Card card)
    {
        List<Card> list = cardService.selectCardList(card);
        ExcelUtil<Card> util = new ExcelUtil<Card>(Card.class);
        return util.exportExcel(list, "card");
    }

    /**
     * 新增卡密信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡密信息
     */
    @RequiresPermissions("fulu:card:add")
    @Log(title = "卡密信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Card card)
    {
        return toAjax(cardService.insertCard(card));
    }

    /**
     * 修改卡密信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Card card = cardService.selectCardById(id);
        mmap.put("card", card);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡密信息
     */
    @RequiresPermissions("fulu:card:edit")
    @Log(title = "卡密信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Card card)
    {
        return toAjax(cardService.updateCard(card));
    }

    /**
     * 删除卡密信息
     */
    @RequiresPermissions("fulu:card:remove")
    @Log(title = "卡密信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cardService.deleteCardByIds(ids));
    }
}
